"""
    循环使用的帧计时器
    CycleTimer --> OnlyTimer
"""
from PyPixelCore.timer.OnlyTimer import OnlyTimer


class CycleTimer(OnlyTimer):
    def __init__(self, max_frame):
        super().__init__(max_frame)
        self.now_frame = 0
        self.type = 1

    def next_frame(self):
        if not self._is_end:
            self.now_frame += 1
            if self.max_frame < self.now_frame:
                self.now_frame = 0
                self._is_end = True

    def reset(self):
        self._is_end = False
        self.now_frame = 0

    def reset_frame(self):
        self.now_frame = 0

    def __str__(self):
        return F"CycleTimer  |is_end: {self._is_end}  max_frame: {self.max_frame}  now_frame: {self.now_frame}"

